﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BruteForceSerializer.Formatting;
using BruteForceSerializer.Normalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace BruteForceSerializer.Tests
{
    [TestClass]
    public class test_Formatter
    {
        [TestMethod]
        public void Objekt_mit_Feld()
        {
            var no = new NormalizedObject("System.String", 0);
            no.AddField("f1", 42);

            var formattedObject = Formatter.Format(no, false);

            Assert.AreEqual(@"{""_Id"":0,""_Type"":""System.String"",""f1"":42}", formattedObject);

			Formatter.DeFormat(formattedObject);
        }

		[TestMethod]
        public void Geschachtelte_Objekte()
        {
			var noParent = new NormalizedObject("System.String", 0);
            var noChild = new NormalizedObject("System.Int32", 1);
            noParent.AddField("child", noChild);

            var formattedObject = Formatter.Format(noParent, false);

			Assert.AreEqual(@"{""_Id"":0,""_Type"":""System.String"",""child"":{""_Id"":1,""_Type"":""System.Int32""}}", formattedObject);
			Formatter.DeFormat(formattedObject);
        }

		[TestMethod]
        public void Objektreferenzen()
        {
			var noParent = new NormalizedObject("System.String", 0);
            var noRef = new NormalizedReference(99);
            noParent.AddField("someObject", noRef);

            var formattedObject = Formatter.Format(noParent, false);

			Assert.AreEqual(@"{""_Id"":0,""_Type"":""System.String"",""someObject"":{""_ObjectId"":99}}", formattedObject);

			Formatter.DeFormat(formattedObject);
        }
    }
}
